﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MinToTray
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            if (Win32.FindWindow(null, Win32.MinToTrayWindowName) != IntPtr.Zero)
            {
                MessageBox.Show("MinToTray already runing...");
                Environment.Exit(0);
            }

            if (AutoStartUpMgr.IsUserAdministrator())
            {
                AutoStartUpMgr.RemoveApplicationFromCurrentUserStartup();
                AutoStartUpMgr.RemoveApplicationFromAllUserStartup();
                AutoStartUpMgr.AddApplicationToAllUserStartup();
            }
            else
            {
                AutoStartUpMgr.RemoveApplicationFromCurrentUserStartup();
                if (!AutoStartUpMgr.IsAllUserStartupAdded())
                {
                    AutoStartUpMgr.AddApplicationToCurrentUserStartup();
                }
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new FrmMain());
        }
    }
}
